<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('偏差分析')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<style>
    select {
        padding-top: 3px !important;
    }

    .select-list {
        margin-top: 5px !important;
    }
</style>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 项目名称
            </div>
            <div class="box-tools pull-right">
                <a type="button" class="btn btn-box-tool" href="#" onclick="project()" title="管理项目"><i
                        class="fa fa-edit"></i></a>
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i
                        class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
                        class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新项目"><i
                        class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="deviationAnalysis-form">
                    <input type="hidden" id="companyId" name="companyId">
                    <input type="hidden" id="proId" name="proId">
                    <div class="col-sm-12">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <p>年份：</p>
                                    <select name="years" class="form-control">
                                        <option value="">请选择</option>
                                        <option th:each="years : ${years}" th:text="${years.years}+'年'"
                                                th:value="${years.years}"></option>
                                    </select>
                                </li>
                                <li>
                                    <p>月份：</p>
                                    <select name="months" class="form-control">
                                        <option value="">请选择</option>
                                        <option th:each="months : ${months}" th:text="${months.monthInYear}+'月'"
                                                th:value="${months.monthInYear}"></option>
                                    </select>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                            class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                            class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add($('#companyId').val()+','+$('#proId').val())">
                    <i class="fa fa-plus"></i> 新增
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<script th:inline="javascript">
    var prefix = ctx + "deviationAnalysis";

    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 300});
        $("#toolbar").hide();
        queryProjectTree();
        queryList();
    });

    function queryList(){
        var options = {
            uniqueId: "id",
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            modalName: "偏差分析",
            columns: [{
                checkbox: true
            },
                {
                    field: 'compName',
                    title: '工程公司'
                },
                {
                    field: 'proName',
                    title: '项目名称'
                },
                {
                    field: 'buildName',
                    title: '楼栋'
                },
                {
                    field: 'years',
                    title: '年份'
                },
                {
                    field: 'months',
                    title: '月份'
                },
                {
                    field: 'type',
                    title: '类型'
                },
                {
                    field: 'reason',
                    title: '原因'
                },
                {
                    title: '操作',
                    align: 'left',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    }

    function queryProjectTree() {
        var fix = ctx + "importantMatter/treeData";
        var options = {
            url: fix,
            expandLevel: 0,
            onClick: zOnClick
        };
        $.tree.init(options);
        function zOnClick(event, treeId, treeNode) {
            if (treeNode.grade == 1) {
                $("#companyId").val(treeNode.id);
                $("#proId").val("");
                $("#toolbar").hide();
                $.table.search();
            } else if (treeNode.grade == 2) {
                $("#companyId").val(treeNode.pId);
                $("#proId").val(treeNode.id);
                $("#toolbar").show();
                $.table.search();
            }
        }
    }

    function project() {
        var url = ctx + "projectManage";
        $.modal.openTab("项目管理", url);
    }

    /* 初始化树组件 > 展开 */
    $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    /* 初始化树组件 > 折叠 */
    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    /* 初始化树组件 > 刷新 */
    $('#btnRefresh').click(function () {
        queryProjectTree();
    });
</script>
</body>
</html>